<h1>Cr&eacute;ation d'un circuit</h1>
<div class="floatStop">
<?php if((empty($_POST['nomCircuit']))||(empty($_POST['paysCircuit']))||(empty($_POST['descriptionCircuit'])))
		{
?>

	<?php 
		$pays = new pays() ;
		$listePays = $pays->getAllNationalites() ;
	?>

	<form method="post" action="index.php?page=20" enctype="multipart/form-data" name="general" >
	<table>
		
		<tr>
			<td align="right" >Nom du circuit* :</td>
			<td>
				
				<input type="text" name="nomCircuit" <?php if(!empty($_POST['nomCircuit'])) { echo "value='".$_POST['nomCircuit']."'" ; } ?> />
			</td>
		</tr>
		<tr>
			<td align="right" >
				Pays* :
			</td>
			<td>
				<select name="paysCircuit" >
				    <option value="0">Choix du pays</option>
				    	<?php 
				    		foreach($listePays as $ligne)
				    		{
				    			//echo "<option value='".$ligne->PAYNUM."'>".$ligne->PAYNAT"</option>" ;
				    			echo "<option value=$ligne->PAYNUM>$ligne->PAYNAT</option>" ;
				    		}
				    	?>
				</select>
			</td>
		</tr>
		<tr>
			<td align="right" >Longueur :</td>
			<td><input type="text" name="longueurCircuit" <?php if(!empty($_POST['longueurCircuit'])) { echo "value='".$_POST['longueurCircuit']."'" ; } ?> /></td>
		</tr>
		<tr>
			<td align="right" >Nombre de spectateurs :</td>
			<td><input type="text" name="spectateursCircuit" <?php if(!empty($_POST['spectateursCircuit'])) { echo "value='".$_POST['spectateursCircuit']."'" ; } ?> /></td>
		</tr>
	
		<tr>
				<td align="right" >Image* :</td>
				<td>
					<img src="images/util/defaut.png" /><br/>
					<input type="file" name="adrImage" />
				</td>
		</tr>
		<tr>
			<td align="right" >Description* :</td>
			<td><textarea name="descriptionCircuit" rows="10" cols="60" ><?php if(!empty($_POST['descriptionCircuit'])) { echo $_POST['descriptionCircuit'] ; } ?></textarea></td>
		</tr>
		<tr>
			<td align="right" ></td>
			<td>
				<input type="submit" /><input type="reset" />
			</td>
		</tr>
	</table>
	</form>
	
<?php 	}

else 
		{
			$circuit = new circuit() ;
			$circuit->setNom(htmlentities(utf8_decode(addslashes($_POST['nomCircuit'])))) ;
			$circuit->setIdPays(htmlentities($_POST['paysCircuit'])) ;
			$circuit->setLongueur(htmlentities(utf8_decode(addslashes($_POST['longueurCircuit'])))) ;
			$circuit->setNbSpectateurs(htmlentities($_POST['spectateursCircuit'])) ;
			
			$dossier = 'images/circuit/' ;
			
			$upload = new uploadUtil() ;
			$upload->upload($_FILES['adrImage'], $dossier) ;
			
			$circuit->setAdrImage(htmlentities(utf8_decode(addslashes($_FILES['adrImage']['name'])))) ;
			$circuit->setText(htmlentities(utf8_decode(addslashes($_POST['descriptionCircuit'])))) ;
			
			$circuit->ajouterCircuit() ;
			
			echo "Circuit ajout&eacute; ! " ;
		}
		
		?></div>